//
//  DKTopItemView.m
//  BTApp
//
//  Created by 丁侃 on 16/4/17.
//  Copyright © 2016年 丁侃. All rights reserved.
//

#import "DKTopItemView.h"
@implementation DKTopItemView

static CGFloat const labelFont = 16.0;

-(void)setItems:(NSArray *)items
{
    _items = items;
    
    //更具传进来的模型,来添加标题
    for (NSInteger i = 0; i < items.count; i ++) {
        
        NSString *item = items[i];
        
        UILabel *laebl = [[UILabel alloc]init];
        laebl.text = item;
        laebl.font = [UIFont systemFontOfSize:labelFont];
        laebl.textAlignment = NSTextAlignmentCenter;
        laebl.textColor = BTNormalNavColor(182, 182, 182, 1);
        
        [self addSubview:laebl];
    }
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat titleY = 0;
    CGFloat titleW = self.width / self.items.count;
    CGFloat titleH = self.height;
    
    for (NSInteger i = 0; i < self.items.count; i ++) {
        
        UILabel *titleLabel = self.subviews[i];
        
        titleLabel.frame = CGRectMake(titleW * i, titleY, titleW, titleH);
        
    }
}


-(UIView *)moveView
{
    if (!_moveView) {
        
        UIView *moveView = [[UIView alloc]init];
        
        //初始化滑块的位置
        moveView.center = CGPointMake(self.width / self.items.count * 0.5, 42);
        moveView.bounds = CGRectMake(0, 0, 30, 4);
        
        [self addSubview:moveView];
        _moveView = moveView;
    }
    return _moveView;
}

@end
